package com.example.myapplication8_1;

import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.SlidingDrawer;
import android.widget.ImageView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    private SlidingDrawer mDrawer;
    private ImageView mHandle;
    private ListView mListView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // 初始化控件
        mDrawer = findViewById(R.id.slidingdraw);
        mHandle = findViewById(R.id.handle);
        mListView = findViewById(R.id.content);

        // 准备数据源
        String[] poems = {
                "《如果您能记住》- 马迪·金",
                "《世界上最远的距离》",
                "《致橡树》- 舒婷",
                "《假如生活欺骗了你》- 普希金",
                "《雨巷》- 戴望舒",
                "《当你老了》- 叶芝",
                "《再别康桥》- 徐志摩",
                "《我孤独的漫游，像一朵云》- 华兹华斯",
                "《斑扎古鲁白玛的沉默》- 扎西拉姆·多多",
                "《乡愁》- 余光中",
                "《一棵开花的树》- 席慕蓉"
        };

        // 设置适配器
        ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, poems);
        mListView.setAdapter(adapter);

        // 监听打开抽屉事件
        mDrawer.setOnDrawerOpenListener(() -> {
            mHandle.setImageResource(R.drawable.down); // 切换为向下箭头
        });

        // 监听关闭抽屉事件
        mDrawer.setOnDrawerCloseListener(() -> {
            mHandle.setImageResource(R.drawable.up); // 切换为向上箭头
        });
    }
}